package com.me.permission;

import java.util.Set;

/**
 * Mybatis 插件：数据权限配置实体类
 *
 * @author ME
 */
public class PermissionObj {

    /**
     * 用来做数据权限条件筛选的 PO(数据库持久对象) -- 用来解决多表关联时，无法明确哪一个实体才是筛选数据权限的 PO
     */
    private Class<?> conditionClazz;

    /**
     * 对于实体中存在多个数据权限列，需要使用的列名在 PermissionColumns注解中的下标，
     * 默认为 0
     */
    private int permissionColumnIndex = 0;

    /**
     * 数据权限列表
     */
    private Set<String> permissionSet;

    /**
     *
     * @param conditionClazz 需要校验数据权限的类
     * @param permissionSet 数据权限列表
     */
    public PermissionObj(Class<?> conditionClazz, Set<String> permissionSet) {
        this.conditionClazz = conditionClazz;
        this.permissionSet = permissionSet;
    }

    /**
     *
     * @param conditionClazz 需要校验数据权限的类
     * @param permissionColumnIndex @PermissionColumns 注解中的列名下标
     * @param permissionSet 数据权限列表
     */
    public PermissionObj(Class<?> conditionClazz, int permissionColumnIndex, Set<String> permissionSet) {
        this.conditionClazz = conditionClazz;
        this.permissionColumnIndex = permissionColumnIndex;
        this.permissionSet = permissionSet;
    }

    public Class<?> getConditionClazz() {
        return conditionClazz;
    }

    public void setConditionClazz(Class<?> conditionClazz) {
        this.conditionClazz = conditionClazz;
    }

    public int getPermissionColumnIndex() {
        return permissionColumnIndex;
    }

    public void setPermissionColumnIndex(int permissionColumnIndex) {
        this.permissionColumnIndex = permissionColumnIndex;
    }

    public Set<String> getPermissionSet() {
        return permissionSet;
    }

    public void setPermissionSet(Set<String> permissionSet) {
        this.permissionSet = permissionSet;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        PermissionObj that = (PermissionObj) o;
        return permissionColumnIndex == that.permissionColumnIndex && conditionClazz.equals(that.conditionClazz);
    }
}
